package utils;

import java.io.UnsupportedEncodingException;

import crypto.HashFunction;

import ArithmeticObjects.*;


/**
 * This class defines specific unmarshalling functions, used to extract certain objects
 * from their marhsalled representation in a ByteTree = node(str,obj).
 * str is a ByteTree representing a string which declares the instance of obj. 
 * @author yuvalshu
 *
 */
public class MarshalServices {
/**
 * Receives a ByteTree bt as input, and returns the instance of the crypt
 * function represented by bt.
 */
	public static Object unmarshalHashFunc(ByteTree bt) throws UnsupportedEncodingException{
		return new HashFunction(bt.getString());
	}
	
	/**
	 * Receives a marshalled ByteTree representing a modular group and returns
	 * the specific modular group represented.
	 * @param bt
	 * @return ModularGroup
	 * @throws Exception - if error accurs in ModularGroup constructor
	 */
	public static ModularGroup unmarshalModGroup(ByteTree bt) throws Exception {
		ByteTree modTree = bt.getChild(1);
		return new ModularGroup(modTree);
	}
}
